/* eslint-disable array-callback-return,no-undef,prefer-destructuring */
import React, { Component } from 'react';
import { Modal, message } from 'antd';
import * as commonConfig from '../../utils/config';
import * as commonFunc from './commonFunc';
import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */
import * as commonUtils from '../../utils/utils'; /* 通用方法 */
import * as commonServices from './../../services/services'; /*   服务类   */
import * as comFunc from './ComFunc'; /* 通用单据方法 */

const { confirm } = Modal;

export default (ChildComponent) => {
  return class extends Component {
    constructor(props) {
      super(props);
      this.state = {};
      this.form = {};
      /*   表单对象   */
    }

    componentWillReceiveProps(nextProps) {
      const {
        formData, currentId, sModelsType, app,
      } = nextProps;
      let {
        employeeConfig, contactColumn, supplyColumn, machineColumn, picFileColumn, eleemployeeColumn, jurgroupColumn, bReceived, userColumn, sischeckphaselogininfoColumn,
      } = nextProps;
      if (commonUtils.isEmptyArr(contactColumn) && formData.length > 0) {
        const sId = currentId !== undefined ? currentId : '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        /* bGrd代表是否是表格 */
        if (sModelsType === 'element/customerInfo') {
          const contactConfig = formData.filter(item => item.bGrd && item.sTbName === 'elecustomercontacts')[0];
          contactColumn = commonFunc.getHeaderConfig(contactConfig);
          const addressConfig = formData.filter(item => item.bGrd && item.sTbName === 'elecustomeraddress')[0];
          const addressColumn = commonFunc.getHeaderConfig(addressConfig);
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.contactConfig = contactConfig;
            config.addressConfig = addressConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetData(masterConfig, contactConfig, addressConfig);
          }
          this.props.onSaveState({
            masterConfig,
            contactConfig,
            contactColumn,
            addressConfig,
            addressColumn,
            sId,
            pageLoading: false,
            ...addState,
          });
        } else if (sModelsType === 'element/supplyInfo') {
          const contactConfig = formData.filter(item => item.bGrd && item.sTbName === 'elesupplycontacts')[0];
          contactColumn = commonFunc.getHeaderConfig(contactConfig);
          const addressConfig = formData.filter(item => item.bGrd && item.sTbName === 'elesupplyaddress')[0];
          const addressColumn = commonFunc.getHeaderConfig(addressConfig);
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.contactConfig = contactConfig;
            config.addressConfig = addressConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetData(masterConfig, contactConfig, addressConfig);
          }
          this.props.onSaveState({
            masterConfig,
            contactConfig,
            contactColumn,
            addressConfig,
            addressColumn,
            sId,
            pageLoading: false,
            ...addState,
          });
        }
      }
      if (commonUtils.isEmptyArr(supplyColumn) && formData.length > 0) {
        const sId = currentId !== undefined ? currentId : '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        /* bGrd代表是否是表格 */
        if (sModelsType === 'element/materialsInfo') {
          const supplyConfig = formData.filter(item => item.bGrd && item.sTbName === 'elematerialssupply')[0];
          supplyColumn = commonFunc.getHeaderConfig(supplyConfig);
          const stockConfig = formData.filter(item => item.bGrd && item.sTbName === 'elematerialsstock')[0];
          const stockColumn = commonFunc.getHeaderConfig(stockConfig);
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.supplyConfig = supplyConfig;
            config.stockConfig = stockConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetMaterialsData(masterConfig, supplyConfig, stockConfig);
          }
          this.props.onSaveState({
            masterConfig,
            supplyConfig,
            supplyColumn,
            stockConfig,
            stockColumn,
            sId,
            pageLoading: false,
            ...addState,
          });
        }
      }
      if (commonUtils.isEmptyArr(machineColumn) && formData.length > 0) {
        const sId = currentId !== undefined ? currentId : '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        /* bGrd代表是否是表格 */
        if (sModelsType === 'element/processInfo') {
          const machineConfig = formData.filter(item => item.bGrd && item.sTbName === 'eleprocessmachine')[0];
          machineColumn = commonFunc.getHeaderConfig(machineConfig);
          const assortConfig = formData.filter(item => item.bGrd && item.sTbName === 'eleprocessassort')[0];
          const assortColumn = commonFunc.getHeaderConfig(assortConfig);
          const outsideConfig = formData.filter(item => item.bGrd && item.sTbName === 'eleprocessoutside')[0];
          const outsideColumn = commonFunc.getHeaderConfig(outsideConfig);
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.machineConfig = machineConfig;
            config.assortConfig = assortConfig;
            config.outsideConfig = outsideConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetProcessData(masterConfig, machineConfig, assortConfig, outsideConfig);
          }
          this.props.onSaveState({
            masterConfig,
            machineConfig,
            machineColumn,
            assortConfig,
            assortColumn,
            outsideConfig,
            outsideColumn,
            sId,
            pageLoading: false,
            ...addState,
          });
        }
      }
      if (commonUtils.isEmptyArr(picFileColumn) && formData.length > 0) {
        const sId = currentId !== undefined ? currentId : '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        /* bGrd代表是否是表格 */
        if (sModelsType === 'element/printInfo') {
          const picFileConfig = formData.filter(item => item.bGrd && item.sTbName === 'eleproductfile')[0];
          picFileColumn = commonFunc.getHeaderConfig(picFileConfig);
          const stockConfig = formData.filter(item => item.bGrd && item.sTbName === 'eleproductstock')[0];
          const stockColumn = commonFunc.getHeaderConfig(stockConfig);
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.picFileConfig = picFileConfig;
            config.stockConfig = stockConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetPrintData(masterConfig, picFileConfig, stockConfig);
          }
          this.props.onSaveState({
            masterConfig,
            picFileConfig,
            picFileColumn,
            stockConfig,
            stockColumn,
            sId,
            pageLoading: false,
            ...addState,
          });
        }
      }
      // 班组信息
      if (commonUtils.isEmptyArr(eleemployeeColumn) && formData.length > 0 && sModelsType === 'element/teamInfo') {
        const sId = currentId !== undefined ? currentId : '';
        const masterConfig = formData.filter(item => !item.bGrd && item.sTbName === 'eleteam')[0];
        const eleemployeeConfig = formData.filter(item => item.bGrd && item.sTbName === 'eleteamemployee')[0];
        eleemployeeColumn = commonFunc.getHeaderConfig(eleemployeeConfig);

        const elemachineConfig = formData.filter(item => item.bGrd && item.sTbName === 'eleteammachine')[0];
        const elemachineColumn = commonFunc.getHeaderConfig(elemachineConfig);

        let addState = {};
        if (sId === '') {
          const config = {};
          config.masterConfig = masterConfig;
          config.employeeConfig = eleemployeeConfig;
          config.machineConfig = elemachineConfig;
          addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
        } else {
          this.handleGetTeamData(masterConfig, eleemployeeConfig, elemachineConfig);
        }
        this.props.onSaveState({
          masterConfig,
          eleemployeeConfig,
          eleemployeeColumn,
          elemachineConfig,
          elemachineColumn,
          sId,
          pageLoading: false,
          ...addState,
        });
      }
      if (commonUtils.isEmptyArr(jurgroupColumn) && formData.length > 0) {
        const sId = currentId !== undefined ? currentId : '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        /* bGrd代表是否是表格 */
        if (sModelsType === 'element/sftloginInfo') {
          const jurgroupConfig = formData.filter(item => item.bGrd && item.sTbName === 'sftlogininfojurisdictiongroup')[0];
          jurgroupColumn = commonFunc.getHeaderConfig(jurgroupConfig);
          const customergroupConfig = formData.filter(item => item.bGrd && item.sTbName === 'sftlogininfocustomergroup')[0];
          const customergroupColumn = commonFunc.getHeaderConfig(customergroupConfig);
          const supplygroupConfig = formData.filter(item => item.bGrd && item.sTbName === 'sftlogininfosupplygroup')[0];
          const supplygroupColumn = commonFunc.getHeaderConfig(supplygroupConfig);
          const persongroupConfig = formData.filter(item => item.bGrd && item.sTbName === 'sftlogininfopersongroup')[0];
          const persongroupColumn = commonFunc.getHeaderConfig(persongroupConfig);
          const processgroupConfig = formData.filter(item => item.bGrd && item.sTbName === 'sftlogininfoprocessgroup')[0];
          const processgroupColumn = commonFunc.getHeaderConfig(processgroupConfig);
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.jurgroupConfig = jurgroupConfig;
            config.customergroupConfig = customergroupConfig;
            config.supplygroupConfig = supplygroupConfig;
            config.persongroupConfig = persongroupConfig;
            config.processgroupConfig = processgroupConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetSflLoginData(masterConfig, jurgroupConfig, customergroupConfig, supplygroupConfig, persongroupConfig, processgroupConfig);
          }
          this.props.onSaveState({
            masterConfig,
            jurgroupConfig,
            jurgroupColumn,
            customergroupConfig,
            customergroupColumn,
            supplygroupConfig,
            supplygroupColumn,
            persongroupConfig,
            persongroupColumn,
            processgroupConfig,
            processgroupColumn,
            sId,
            pageLoading: false,
            ...addState,
          });
        }
      }
      if ((bReceived === undefined || !bReceived) && formData.length > 0 && sModelsType === 'system/sisformulaInfo') {
        const sId = currentId !== undefined ? currentId : '';
        const masterConfig = formData.filter(item => !item.bGrd && item.sTbName === 'sisformula')[0];
        const paramConfig = formData.filter(item => item.bGrd && item.sTbName === 'sisformulaparam')[0];
        this.handleGetSlaveData('Set', 'param', paramConfig);
        let addState = {};

        const systemFunctionData = [];
        systemFunctionData.push({ value: 'Max(round(变量,0))', sName: commonFunc.showMessage(app.commonConst, 'sysMaxInteger') });
        systemFunctionData.push({ value: 'round(变量，小数位数)', sName: commonFunc.showMessage(app.commonConst, 'sysRounding') });
        systemFunctionData.push({ value: 'Min(round(变量,0))', sName: commonFunc.showMessage(app.commonConst, 'sysMinInteger') });

        if (sId === '') {
          const config = {};
          config.masterConfig = masterConfig;
          config.paramConfig = paramConfig;
          addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
        } else {
          this.handleGetSlaveData('One', undefined, masterConfig);
        }
        bReceived = true;
        this.props.onSaveState({
          masterConfig,
          paramConfig,
          sId,
          systemFunctionData,
          bReceived,
          pageLoading: false,
          ...addState,
        });
      }
      if ((bReceived === undefined || !bReceived) && formData.length > 0 && sModelsType === 'element/machineInfo') {
        const sId = currentId !== undefined ? currentId : '';
        const masterConfig = formData.filter(item => !item.bGrd && item.sTbName === 'elemachine')[0];
        let addState = {};
        if (sId === '') {
          const config = {};
          config.masterConfig = masterConfig;
          config.paramConfig = paramConfig;
          addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
        } else {
          this.handleGetSlaveData('One', null, masterConfig);
        }
        bReceived = true;
        this.props.onSaveState({
          bReceived,
          expand: true,
          masterConfig,
          sId,
          pageLoading: false,
          ...addState,
        });
      }
      if (commonUtils.isEmptyArr(userColumn) && formData.length > 0) {
        const sId = currentId !== undefined ? currentId : '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd && item.sTbName === 'elecheckmodel')[0];
        /* bGrd代表是否是表格 */
        if (sModelsType === 'element/checkModelInfo') {
          const userConfig = formData.filter(item => item.bGrd && item.sTbName === 'elecheckmodeluser')[0];
          userColumn = commonFunc.getHeaderConfig(userConfig);
          const phaseConfig = formData.filter(item => item.bGrd && item.sTbName === 'elecheckmodelphase')[0];
          const phaseColumn = commonFunc.getHeaderConfig(phaseConfig);
          const conditionConfig = formData.filter(item => item.bGrd && item.sTbName === 'elecheckmodelcondition')[0];
          const conditionColumn = commonFunc.getHeaderConfig(conditionConfig);
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.userConfig = userConfig;
            config.phaseConfig = phaseConfig;
            config.conditionConfig = conditionConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetCheckModelData(masterConfig, userConfig, phaseConfig, conditionConfig);
          }
          this.props.onSaveState({
            masterConfig,
            userConfig,
            userColumn,
            phaseConfig,
            phaseColumn,
            conditionConfig,
            conditionColumn,
            sId,
            pageLoading: false,
            ...addState,
          });
        }
      }
      if (commonUtils.isEmptyArr(sischeckphaselogininfoColumn) && formData.length > 0) {
        const sId = currentId !== undefined ? currentId : '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd && item.sTbName === 'sischeckphase')[0];
        /* bGrd代表是否是表格 */
        if (sModelsType === 'element/checkPhaseInfo') {
          const sischeckphaselogininfoConfig = formData.filter(item => item.bGrd && item.sTbName === 'sischeckphaselogininfo')[0];
          sischeckphaselogininfoColumn = commonFunc.getHeaderConfig(sischeckphaselogininfoConfig);
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            config.sischeckphaselogininfoConfig = sischeckphaselogininfoConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetCheckPhaseData(masterConfig, sischeckphaselogininfoConfig);
          }
          this.props.onSaveState({
            masterConfig,
            sischeckphaselogininfoConfig,
            sischeckphaselogininfoColumn,
            sId,
            pageLoading: false,
            ...addState,
          });
        }
      }
      if ((bReceived === undefined || !bReceived) && formData.length > 0 && sModelsType === 'sis/paymentTerms') {
        const sId = currentId !== undefined ? currentId : '';
        const masterConfig = formData.filter(item => !item.bGrd && item.sTbName === 'sispayment')[0];

        const firstRow = masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName === 'sName');
        const secondRow = masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName === 'sType');
        masterConfig.rowGdsconfig = [{ gdsconfigformslave: firstRow }, { gdsconfigformslave: secondRow }];

        let addState = {};
        if (sId === '') {
          const config = {};
          config.masterConfig = masterConfig;
          addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
        } else {
          this.handleGetSlaveData('One', null, masterConfig);
        }
        bReceived = true;
        this.props.onSaveState({
          bReceived,
          expand: true,
          masterConfig,
          sId,
          pageLoading: false,
          ...addState,
        });
      }
      if (commonUtils.isEmptyArr(employeeConfig) && formData.length > 0) {
        const sId = currentId !== undefined ? currentId : '';
        /* 数据Id */
        const masterConfig = formData.filter(item => !item.bGrd)[0];
        /* bGrd代表是否是表格 */
        if (sModelsType === 'element/employeeInfo') {
          employeeConfig = masterConfig;
          let addState = {};
          if (sId === '') {
            const config = {};
            config.masterConfig = masterConfig;
            addState = this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
          } else {
            this.handleGetEleemployeeData(masterConfig);
          }
          this.props.onSaveState({
            masterConfig,
            employeeConfig,
            sId,
            pageLoading: false,
            ...addState,
          });
        }
      }
    }

    shouldComponentUpdate(nextProps, nextState) {
      let flag = true;
      /* 追加弹出框数值回填放行判断ppopupPane */
      if (nextProps.sTabId === nextProps.app.currentPane.key || ((nextProps.app.ppopupPane !== undefined
        && nextProps.app.ppopupPane.mainConfig !== undefined)
        ? nextProps.sTabId === nextProps.app.ppopupPane.mainConfig.key : false)) {
        if (nextState.disabled !== this.state.disabled) {
          return true;
        }
        flag = true;
      } else {
        flag = false;
      }
      return flag;
    }
    componentWillUpdate(nextProps) {
      const {
        masterData, sModelsType, elemachineData, contactData, addressData, masterConfig,
      } = nextProps;

      if (sModelsType === 'element/teamInfo' && masterData !== undefined) {
        if (commonUtils.isNotEmptyObject(elemachineData)) {
          elemachineData.forEach((row, index) => {
            if (row.sMachineId === masterData.sMachineId) {
              elemachineData[index].bDefault = true;
            } else {
              elemachineData[index].bDefault = false;
            }
          });
        }
      } else if ((sModelsType === 'element/customerInfo' || sModelsType === 'element/supplyInfo') && masterData !== undefined) {
        if (commonUtils.isNotEmptyObject(contactData)) {
          contactData.forEach((row, index) => {
            if (row.sContacts === masterData.sContacts) {
              contactData[index].bDefault = true;
            } else {
              contactData[index].bDefault = false;
            }
          });
        }
        if (commonUtils.isNotEmptyObject(addressData)) {
          addressData.forEach((row, index) => {
            if (row.csProvince_sCity_sArea === masterData.csProvince_sCity_sArea && row.sDetailAddress === masterData.sCompanyAddress) {
              addressData[index].bDefault = true;
            } else {
              addressData[index].bDefault = false;
            }
          });
        }
      } else if (sModelsType === 'system/sisformulaInfo' && commonUtils.isNotEmptyObject(masterData)) {
        masterData.sFormulaMemo = masterData.sFormula;
      } else if (sModelsType === 'sis/paymentTerms' && commonUtils.isNotEmptyObject(masterData)) {
        const { rowGdsconfig } = masterConfig;
        if (commonUtils.isNotEmptyArr(rowGdsconfig) && rowGdsconfig.length === 2) {
          if (masterData.sType === 'deliver') {
            const rows = {};
            const threeRows = masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName === 'iAfterDeliverDay');
            rows.gdsconfigformslave = threeRows;
            rowGdsconfig.push(rows);
            this.props.onSaveState({ masterConfig });
          } else if (masterData.sType === 'month') {
            const rows = {};
            const threeRows = masterConfig.gdsconfigformslave.filter(item => item.bVisible && (item.sName === 'iMonth' || item.sName === 'iDay'));
            rows.gdsconfigformslave = threeRows;
            rowGdsconfig.push(rows);
            this.props.onSaveState({ masterConfig });
          }
        }
      }
    }
    /**   获取主表、联系人、地址表数据   */
    handleGetData = (masterConfig, contactConfig, addressConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
      this.props.handleGetDataSet({
        name: 'contact', configData: contactConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'address', configData: addressConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };
    /**   获取主表、图片文件、仓库表数据   */
    handleGetPrintData = (masterConfig, picFileConfig, stockConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
      this.props.handleGetDataSet({
        name: 'picFile', configData: picFileConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'stock', configData: stockConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };
    /**   获取主表、创建者、审核阶段、审核条件数据   */
    handleGetCheckModelData = (masterConfig, userConfig, phaseConfig, conditionConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
      this.props.handleGetDataSet({
        name: 'user', configData: userConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'phase', configData: phaseConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'condition', configData: conditionConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };
    /**   获取员工数据   */
    handleGetEleemployeeData = (masterConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
    };
    /**   获取主表、审核人员数据   */
    handleGetCheckPhaseData = (masterConfig, sischeckphaselogininfoConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
      this.props.handleGetDataSet({
        name: 'sischeckphaselogininfo', configData: sischeckphaselogininfoConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };

    /**   获取主表、询价信息、仓库表数据   */
    handleGetMaterialsData = (masterConfig, supplyConfig, stockConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
      this.props.handleGetDataSet({
        name: 'supply', configData: supplyConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'stock', configData: stockConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };

    /**   获取用户信息数据   */
    handleGetSflLoginData = (masterConfig, jurgroupConfig, customergroupConfig, supplygroupConfig, persongroupConfig, processgroupConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
      this.props.handleGetDataSet({
        name: 'jurgroup', configData: jurgroupConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'customergroup', configData: customergroupConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'supplygroup', configData: supplygroupConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'persongroup', configData: persongroupConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'processgroup', configData: processgroupConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };

    /**   获取主表、对应机台、配套工序、发外公式表数据   */
    handleGetProcessData = (masterConfig, machineConfig, assortConfig, outsideConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
      this.props.handleGetDataSet({
        name: 'machine', configData: machineConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'assort', configData: assortConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'outside', configData: outsideConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };
    /**   获取班组主表、员工、机台表数据   */
    handleGetTeamData = (masterConfig, eleemployeeConfig, elemachineConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      this.props.handleGetDataOne({
        name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
      });
      this.props.handleGetDataSet({
        name: 'eleemployee', configData: eleemployeeConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
      this.props.handleGetDataSet({
        name: 'elemachine', configData: elemachineConfig, condition: { sSqlCondition: { sParentId: sId } },
      });
    };
    handleGetSisformulaData = (masterConfig) => {
      this.handleGetSlaveData('One', null, masterConfig);
    }

    handleGetSlaveData = (getType, sName, currConfig) => {
      const { currentId } = this.props;
      /* 当前页签数据 */
      const sId = currentId !== undefined ? currentId : '';
      if (getType === 'One') {
        this.props.handleGetDataOne({
          name: 'master', configData: currConfig, condition: { sId, pageSize: '', pageNum: '' },
        });
      }
      if (getType === 'Set') {
        this.props.handleGetDataSet({
          name: sName, configData: currConfig, condition: { sSqlCondition: { sParentId: sId } },
        });
      }
    }
    /** 主表控件是否全部显示 */
    handleToggle = () => {
      const { expand } = this.props;
      this.props.onSaveState({ expand: !expand });
    };
    /*   取消操作  */
    handleCancel = (obj) => {
      /*   待用数据声明   */
      const {
        masterConfig, contactConfig, addressConfig, supplyConfig, stockConfig, sModelsType, machineConfig, assortConfig, outsideConfig, picFileConfig, userConfig, sischeckphaselogininfoConfig, phaseConfig, conditionConfig, eleemployeeConfig, elemachineConfig, jurgroupConfig, customergroupConfig, supplygroupConfig, persongroupConfig, processgroupConfig,
      } = this.props;
      if (sModelsType === 'element/customerInfo' || sModelsType === 'element/supplyInfo') {
        const onGetDataOk = this.handleGetData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig, contactConfig, addressConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/materialsInfo') {
        const onGetDataOk = this.handleGetMaterialsData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig, supplyConfig, stockConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/processInfo') {
        const onGetDataOk = this.handleGetProcessData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig, machineConfig, assortConfig, outsideConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/printInfo') {
        const onGetDataOk = this.handleGetPrintData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig, picFileConfig, stockConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/teamInfo') {
        const onGetDataOk = this.handleGetTeamData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig, eleemployeeConfig, elemachineConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/sftloginInfo') {
        const onGetDataOk = this.handleGetSflLoginData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig, jurgroupConfig, customergroupConfig, supplygroupConfig, persongroupConfig, processgroupConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'system/sisformulaInfo') {
        const onGetDataOk = this.handleGetSlaveData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk('One', null, masterConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/machineInfo') {
        const onGetDataOk = this.handleGetSlaveData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk('One', null, masterConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/checkModelInfo') {
        const onGetDataOk = this.handleGetCheckModelData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig, userConfig, phaseConfig, conditionConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/checkPhaseInfo') {
        const onGetDataOk = this.handleGetCheckPhaseData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig, sischeckphaselogininfoConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'sis/paymentTerms') {
        const onGetDataOk = this.handleGetSlaveData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk('One', null, masterConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      } else if (sModelsType === 'element/employeeInfo') {
        const onGetDataOk = this.handleGetEleemployeeData;
        const onSaveStateOk = this.props.onSaveState;
        confirm({
          title: obj.title,
          onOk() {
            onGetDataOk(masterConfig);
            onSaveStateOk({ enabled: false });
          },
          onCancel() {
          },
        });
      }
    };
    handleGetTableData = () => {
      const {
        sModelsType, masterConfig, contactConfig, addressConfig, machineConfig, assortConfig, outsideConfig, supplyConfig, stockConfig, picFileConfig, eleemployeeConfig, elemachineConfig, jurgroupConfig, customergroupConfig, supplygroupConfig, persongroupConfig, processgroupConfig, paramConfig, userConfig, phaseConfig, conditionConfig, sischeckphaselogininfoConfig,
      } = this.props;
      if (sModelsType === 'element/customerInfo' || sModelsType === 'element/supplyInfo') {
        this.handleGetData(masterConfig, contactConfig, addressConfig);
      } else if (sModelsType === 'element/processInfo') {
        this.handleGetProcessData(masterConfig, machineConfig, assortConfig, outsideConfig);
      } else if (sModelsType === 'element/materialsInfo') {
        this.handleGetMaterialsData(masterConfig, supplyConfig, stockConfig);
      } else if (sModelsType === 'element/printInfo') {
        this.handleGetPrintData(masterConfig, picFileConfig, stockConfig);
      } else if (sModelsType === 'element/teamInfo') {
        this.handleGetTeamData(masterConfig, eleemployeeConfig, elemachineConfig);
      } else if (sModelsType === 'element/sftloginInfo') {
        this.handleGetSflLoginData(masterConfig, jurgroupConfig, customergroupConfig, supplygroupConfig, persongroupConfig, processgroupConfig);
      } else if (sModelsType === 'element/machineInfo' || sModelsType === 'sis/paymentTerms') {
        this.handleGetSlaveData('One', null, masterConfig);
      } else if (sModelsType === 'system/sisformulaInfo') {
        this.handleGetSlaveData('Set', 'param', paramConfig);
        this.handleGetSlaveData('One', undefined, masterConfig);
      } else if (sModelsType === 'element/checkModelInfo') {
        this.handleGetCheckModelData(masterConfig, userConfig, phaseConfig, conditionConfig);
      } else if (sModelsType === 'element/checkPhaseInfo') {
        this.handleGetCheckPhaseData(masterConfig, sischeckphaselogininfoConfig);
      } else if (sModelsType === 'element/employeeInfo') {
        this.handleGetEleemployeeData(masterConfig);
      }
    };
    /**   点击修改按钮操作   */
    handleEdit = () => {
      this.handleGetTableData();
      this.props.onSaveState({ enabled: true });
    };
    /* 删除 */
    handleDel = (obj) => {
      const props = { ...this.props, ...this.state };
      const onOkDel = this.handleOkDel;
      confirm({
        title: obj.title,
        onOk() {
          onOkDel(props);
        },
        onCancel() {
        },
      });
    };
    /* 确定要删除 */
    handleOkDel = async (props) => {
      /*   数据参数   */
      const {
        token, sModelsId, masterConfig, masterData, contactConfig, addressConfig, supplyConfig, stockConfig, machineConfig, assortConfig, outsideConfig, picFileConfig, eleemployeeConfig, elemachineConfig, jurgroupConfig, customergroupConfig, supplygroupConfig, persongroupConfig, processgroupConfig, userConfig, sischeckphaselogininfoConfig, phaseConfig, conditionConfig, sModelsType,
      } = props;
      let value = {};
      if (sModelsType === 'element/customerInfo' || sModelsType === 'element/supplyInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [
              {
                tableName: contactConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: addressConfig.sTbName,
                relationName: 'sParentId',
              }],
          },
        };
      } else if (sModelsType === 'element/materialsInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [
              {
                tableName: supplyConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: stockConfig.sTbName,
                relationName: 'sParentId',
              }],
          },
        };
      } else if (sModelsType === 'element/processInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [
              {
                tableName: machineConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: assortConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: outsideConfig.sTbName,
                relationName: 'sParentId',
              }],
          },
        };
      } else if (sModelsType === 'element/printInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [
              {
                tableName: picFileConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: stockConfig.sTbName,
                relationName: 'sParentId',
              }],
          },
        };
      } else if (sModelsType === 'element/teamInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [
              {
                tableName: eleemployeeConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: elemachineConfig.sTbName,
                relationName: 'sParentId',
              }],
          },
        };
      } else if (sModelsType === 'element/sftloginInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [
              {
                tableName: jurgroupConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: customergroupConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: supplygroupConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: persongroupConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: processgroupConfig.sTbName,
                relationName: 'sParentId',
              }],
          },
        };
      } else if (sModelsType === 'system/sisformulaInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [],
          },
        };
      } else if (sModelsType === 'element/machineInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [],
          },
        };
      } else if (sModelsType === 'element/checkModelInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [
              {
                tableName: userConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: phaseConfig.sTbName,
                relationName: 'sParentId',
              }, {
                tableName: conditionConfig.sTbName,
                relationName: 'sParentId',
              }],
          },
        };
      } else if (sModelsType === 'element/checkPhaseInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [
              {
                tableName: sischeckphaselogininfoConfig.sTbName,
                relationName: 'sParentId',
              }],
          },
        };
      } else if (sModelsType === 'sis/paymentTerms') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [],
          },
        };
      } else if (sModelsType === 'element/employeeInfo') {
        value = {
          sClientType: '1',
          data: {
            sMasterTable: masterConfig.sTbName,
            sId: [masterData.sId],
            sSlaveTable: [],
          },
        };
      }
      const url = `${commonConfig.server_host}business/delMasSlaBusinessData?sModelsId=${sModelsId}`;
      /*   接收返回值   */
      const { data } = await commonServices.postValueService(token, value, url);
      if (data.code === 1) {
        /*   数据删除成功   */
        if (this.props.app.currentPane.refresh !== undefined) {
          this.props.app.currentPane.refresh();
        }
        this.handleDelDataSuccess(props);
      } else { /*   失败   */
        comFunc.handleCommonFail({ ...this.props, ...this.state }, data);
      }
    };
    /* 数据删除成功跳转到新路由即pane */
    handleDelDataSuccess = (props) => {
      const { app } = props;
      let { panes, currentPane } = app;
      /* 删除单据后退出当前路由后,标签panes变化后的集合 */
      panes = panes.filter(pane => pane.key !== currentPane.key);
      /* 跳转到panes集合的最后一个路由，因为panes集合一定含有主页路由所以panes的集合大于等于1 */
      currentPane = panes[panes.length - 1];
      this.props.onRemovePane(panes, currentPane);
    };
    /**   toolbar校验保存   */
    handleValidateSave = async () => {
      this.form.validateFieldsAndScroll((err) => {
        /*   验证通过与不通过走不同的流程   */
        if (err) { /*   验证失败   */
          /*   直接渲染显示错误提示   */
          for (const key of Object.keys(err)) {
            message.warning(err[key].errors[0].message);
          }
        } else { /*   验证成功   */
          const {
            masterConfig, masterData, supplyConfig, supplyData, supplyDelData, stockConfig, stockData, stockDelData, contactConfig, contactData, contactDelData, addressConfig, addressData, addressDelData, sModelsType, machineConfig, machineData, machineDelData, assortConfig, assortData, assortDelData, outsideConfig, outsideData, outsideDelData, picFileConfig, picFileData, picFileDelData, eleemployeeConfig, eleemployeeData, eleemployeeDelData, elemachineConfig, elemachineData, elemachineDelData, jurgroupConfig, jurgroupData, jurgroupDelData, customergroupConfig, customergroupData, customergroupDelData, supplygroupConfig, supplygroupData, supplygroupDelData, persongroupConfig, persongroupData, persongroupDelData, processgroupConfig, processgroupData, processgroupDelData, userConfig, sischeckphaselogininfoConfig, sischeckphaselogininfoData, sischeckphaselogininfoDelData, phaseConfig, conditionConfig, userData, phaseData, conditionData, userDelData, phaseDelData, conditionDelData,
          } = this.props;
          const data = [];
          data.push(commonBusiness.mergeData('master', masterConfig.sTbName, [masterData]));
          if (sModelsType === 'element/customerInfo' || sModelsType === 'element/supplyInfo') {
            if (!commonBusiness.validateTable(contactConfig, contactData) || !commonBusiness.validateTable(addressConfig, addressData)) {
              return;
            }
            data.push(commonBusiness.mergeData('contact', contactConfig.sTbName, contactData, contactDelData));
            data.push(commonBusiness.mergeData('address', addressConfig.sTbName, addressData, addressDelData));
          } else if (sModelsType === 'element/materialsInfo') {
            if (!commonBusiness.validateTable(supplyConfig, supplyData) || !commonBusiness.validateTable(stockConfig, stockData)) {
              return;
            }
            data.push(commonBusiness.mergeData('supply', supplyConfig.sTbName, supplyData, supplyDelData));
            data.push(commonBusiness.mergeData('stock', stockConfig.sTbName, stockData, stockDelData));
          } else if (sModelsType === 'element/processInfo') {
            if (!commonBusiness.validateTable(machineConfig, machineData) || !commonBusiness.validateTable(assortConfig, assortData) || !commonBusiness.validateTable(outsideConfig, outsideData)) {
              return;
            }
            data.push(commonBusiness.mergeData('machine', machineConfig.sTbName, machineData, machineDelData));
            data.push(commonBusiness.mergeData('assort', assortConfig.sTbName, assortData, assortDelData));
            data.push(commonBusiness.mergeData('outside', outsideConfig.sTbName, outsideData, outsideDelData));
          } else if (sModelsType === 'element/printInfo') {
            if (!commonBusiness.validateTable(picFileConfig, picFileData) || !commonBusiness.validateTable(stockConfig, stockData)) {
              return;
            }
            data.push(commonBusiness.mergeData('picFile', picFileConfig.sTbName, picFileData, picFileDelData));
            data.push(commonBusiness.mergeData('stock', stockConfig.sTbName, stockData, stockDelData));
          } else if (sModelsType === 'element/teamInfo') {
            if (!commonBusiness.validateTable(eleemployeeConfig, eleemployeeData) || !commonBusiness.validateTable(elemachineConfig, elemachineData)) {
              return;
            }
            data.push(commonBusiness.mergeData('eleemployee', eleemployeeConfig.sTbName, eleemployeeData, eleemployeeDelData));
            data.push(commonBusiness.mergeData('elemachine', elemachineConfig.sTbName, elemachineData, elemachineDelData));
          } else if (sModelsType === 'element/sftloginInfo') {
            if (!commonBusiness.validateTable(jurgroupConfig, jurgroupData) || !commonBusiness.validateTable(customergroupConfig, customergroupData) || !commonBusiness.validateTable(supplygroupConfig, supplygroupData) || !commonBusiness.validateTable(persongroupConfig, persongroupData) || !commonBusiness.validateTable(processgroupConfig, processgroupData)) {
              return;
            }
            data.push(commonBusiness.mergeData('jurgroup', jurgroupConfig.sTbName, jurgroupData, jurgroupDelData));
            data.push(commonBusiness.mergeData('customergroup', customergroupConfig.sTbName, customergroupData, customergroupDelData));
            data.push(commonBusiness.mergeData('supplygroup', supplygroupConfig.sTbName, supplygroupData, supplygroupDelData));
            data.push(commonBusiness.mergeData('persongroup', persongroupConfig.sTbName, persongroupData, persongroupDelData));
            data.push(commonBusiness.mergeData('processgroup', processgroupConfig.sTbName, processgroupData, processgroupDelData));
          } else if (sModelsType === 'element/checkModelInfo') {
            if (!commonBusiness.validateTable(userConfig, userData) || !commonBusiness.validateTable(phaseConfig, phaseData) || !commonBusiness.validateTable(conditionConfig, conditionData)) {
              return;
            }
            data.push(commonBusiness.mergeData('user', userConfig.sTbName, userData, userDelData));
            data.push(commonBusiness.mergeData('phase', phaseConfig.sTbName, phaseData, phaseDelData));
            data.push(commonBusiness.mergeData('condition', conditionConfig.sTbName, conditionData, conditionDelData));
          } else if (sModelsType === 'element/checkPhaseInfo') {
            if (!commonBusiness.validateTable(sischeckphaselogininfoConfig, userData)) {
              return;
            }
            data.push(commonBusiness.mergeData('sischeckphaselogininfo', sischeckphaselogininfoConfig.sTbName, sischeckphaselogininfoData, sischeckphaselogininfoDelData));
          }
          this.handleSaveData({ data, sClientType: '1' });
        }
      });
    };
    /**   toolbar保存   */
    handleSaveData = async (params) => {
      const {
        token, sModelsId, masterData,
      } = this.props;
      const returnData = await commonBusiness.saveData({ token, value: params, sModelsId });
      if (commonUtils.isNotEmptyObject(returnData)) {
        this.props.onSaveState({
          enabled: false, currentId: masterData.sId === undefined ? masterData.sid : masterData.sId,
        });
        this.handleGetTableData();
        commonUtils.clearStoreDropDownData();
        return true;
      } else {
        return false;
      }
    };
    /**   表单回带   */
    handleForm = (form) => {
      this.form = form;
    };
    /*  上一条、下一条、首条、末条 */
    handleSearchData = async (handleType) => {
      const {
        sModelsId, app, currentIndexFlag, currentPageNo,
      } = this.props;
      const { currentPane, token } = app;
      const {
        pages, sFilterOrderBy, bFilter, sListFormmasterId, currentIndex,
      } = currentPane;
      let currentPosition = currentIndexFlag ? currentPageNo : (((pages.current - 1) * commonConfig.pageSize) + Number.parseInt(currentIndex, 10)) + 1;
      if (handleType === 'first') {
        currentPosition = 1;
      } else if (handleType === 'end') {
        currentPosition = pages.total;
      }

      const value = {
        sClientType: '1',
        sFilterOrderBy,
        bFilter,
        sListFormmasterId,
        currentPosition,
        handleType,
        iCountSum: pages.total,
      };
      const url = `${commonConfig.server_host}business/getBusinessDataByIndex?sModelsId=${sModelsId}`;
      /*   接收返回值   */
      const { data } = await commonServices.postValueService(token, value, url);
      /*   接收返回值   */
      /*   成功的话刷新页面(同步主表和从表数据),不成功就弹出错误提示   */
      if (data.code === 1) {
        /*   数据查询成功   */
        const returnData = data.dataset.rows[0];
        this.props.onSaveState({
          currentIndexFlag: true,
          currentPageNo: returnData.currentPosition,
          currentId: returnData.sId,
          searchUpDownData: {},
          slaveSelectedRowKeys: [],
        });
        this.handleGetTableData();
      } else { /*   失败   */
        comFunc.handleCommonFail({ ...this.props, ...this.state }, data);
      }
    };
    /* 切换作废状态 */
    handleOkChangeInvaild = async (props) => {
      const {
        sModelsId, masterData, masterConfig, handleType,
      } = props;
      const value = {
        sClientType: '1',
        sId: [masterData.sId],
        sTableName: masterConfig.sTbName,
        handleType,
        sBooleanCheck: false,
      };
      const url = `${commonConfig.server_host}checkModel/updatebInvalid?sModelsId=${sModelsId}`;
      const { data } = await commonServices.postValueService(props.app.token, value, url);
      if (data.code === 1) {
        message.success(data.msg);
        masterData.bInvalid = handleType === 'toVoid'; /* 作废状态 */
        this.props.onSaveState({ masterData });
        /*  审核(消审)后刷新跳转路由数据（commonList）的数据 */
        props.app.currentPane.refresh();
      } else {
        this.props.getServiceError(data);
      }
    };

    /* 作废、取消作废的公用函数 */
    handleInvalid = (obj) => {
      const props = { ...this.props, ...this.state, ...obj };
      const onOkInvaild = this.handleOkChangeInvaild;
      confirm({
        title: obj.title,
        onOk() {
          onOkInvaild(props);
        },
        onCancel() {
        },
      });
    };
    /**  点击新增按钮   */
    handleAdd = (config, copyTo, isWait) => {
      /*   外置处理业务   */
      const { sModelsId, sModelsType } = this.props;
      let masterConfig = commonUtils.isEmptyObject(config) ? {} : config.masterConfig;
      if (!isWait) {
        masterConfig = this.props.masterConfig;
      }
      const masterData = commonFunc.getDefaultData(masterConfig);
      masterData.handleType = 'add';
      masterData.sId = commonUtils.createSid();
      masterData.sFormId = sModelsId;
      let state = {};
      if (sModelsType === 'element/customerInfo') {
        masterData.maxBillNo = 'sCustomerNo';
        state = {
          masterData,
          contactData: [],
          addressData: [],
          enabled: true,
        };
      } else if (sModelsType === 'element/supplyInfo') {
        masterData.maxBillNo = 'sSupplyNo';
        state = {
          masterData,
          contactData: [],
          addressData: [],
          enabled: true,
        };
      } else if (sModelsType === 'element/materialsInfo') {
        masterData.maxBillNo = 'sMaterialsNo';
        state = {
          masterData,
          supplyData: [],
          stockData: [],
          enabled: true,
        };
      } else if (sModelsType === 'element/processInfo') {
        masterData.maxBillNo = 'sProcessNo';
        state = {
          masterData,
          machineData: [],
          assortData: [],
          outsideData: [],
          enabled: true,
        };
      } else if (sModelsType === 'element/printInfo') {
        masterData.maxBillNo = 'sProductNo';
        state = {
          masterData,
          picFileData: [],
          stockData: [],
          enabled: true,
        };
      } else if (sModelsType === 'element/teamInfo') {
        masterData.maxBillNo = 'sTeamNo';
        state = {
          masterData,
          eleemployeeData: [],
          elemachineData: [],
          enabled: true,
        };
      } else if (sModelsType === 'element/sftloginInfo') {
        state = {
          masterData,
          jurgroupData: [],
          customergroupData: [],
          supplygroupData: [],
          persongroupData: [],
          processgroupData: [],
          enabled: true,
        };
      } else if (sModelsType === 'system/sisformulaInfo') {
        state = {
          masterData,
          paramData: [],
          enabled: true,
        };
      } else if (sModelsType === 'element/machineInfo') {
        masterData.maxBillNo = 'sMachineNo';
        state = {
          masterData,
          enabled: true,
        };
      } else if (sModelsType === 'sis/paymentTerms') {
        // masterData.maxBillNo = 'sMachineNo';
        state = {
          masterData,
          enabled: true,
        };
      } else if (sModelsType === 'element/checkModelInfo') {
        state = {
          masterData,
          userData: [],
          phaseData: [],
          conditionData: [],
          enabled: true,
        };
      } else if (sModelsType === 'element/checkPhaseInfo') {
        state = {
          masterData,
          sischeckphaselogininfoData: [],
          enabled: true,
        };
      } else if (sModelsType === 'sis/paymentTerms') {
        state = {
          masterData,
          enabled: true,
        };
      } else if (sModelsType === 'element/employeeInfo') {
        masterData.maxBillNo = 'sEmployeeNo';
        state = {
          masterData,
          enabled: true,
        };
      }
      if (isWait) {
        return state;
      }
      this.props.onSaveState(state);
    };
    /** 表格数据更改 */
    // name 不写完整的state名称作用为了要用到total // (name, changeValue, sId, dropDownData)
    handleTableChange = (name, sFieldName, changeValue, sId, dropDownData) => {
      /*   从CommonBase获取默认参数   */
      const {
        [`${name}Data`]: tableData, masterData, sModelsType, app,
      } = this.props;
      const iIndex = tableData.findIndex(item => item.sId === sId);
      const tableDataRow = this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
      const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') ? 'Product' : 'Materials';
      tableData[iIndex] = commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, tableDataRow);
      if (name === 'contact') {
        if (tableData[iIndex].bDefault === true) {
          masterData.sContacts = tableData[iIndex].sContacts;
          masterData.sPhone1 = tableData[iIndex].sPhone1;
          masterData.sMobile = tableData[iIndex].sMobile;
          masterData.sEmail = tableData[iIndex].sEmail;
          masterData.handleType = masterData.handleType === 'add' ? 'add' : 'update';
          tableData.forEach((item, i) => {
            if (i !== iIndex) {
              tableData[i].bDefault = false;
            }
          });
        } else if (tableData[iIndex].bDefault === false) {
          masterData.handleType = masterData.handleType === 'add' ? 'add' : 'update';
          masterData.sContacts = undefined;
          masterData.sPhone1 = undefined;
          masterData.sMobile = undefined;
          masterData.sEmail = undefined;
        }
        this.props.onSaveState({ [`${name}Data`]: tableData, masterData });
      } else if (name === 'address') {
        if (tableData[iIndex].bDefault === true) {
          masterData.csProvince_sCity_sArea = tableData[iIndex].csProvince_sCity_sArea;
          masterData.sCompanyAddress = tableData[iIndex].sDetailAddress;
          masterData.sProvince = tableData[iIndex].sProvince;
          masterData.sCity = tableData[iIndex].sCity;
          masterData.sArea = tableData[iIndex].sArea;
          masterData.handleType = masterData.handleType === 'add' ? 'add' : 'update';
          tableData.forEach((item, i) => {
            if (i !== iIndex) {
              tableData[i].bDefault = false;
            }
          });
        } else if (tableData[iIndex].bDefault === false) {
          masterData.handleType = masterData.handleType === 'add' ? 'add' : 'update';
          masterData.csProvince_sCity_sArea = undefined;
          masterData.sCompanyAddress = undefined;
          masterData.sProvince = undefined;
          masterData.sCity = undefined;
          masterData.sArea = undefined;
        }
        this.props.onSaveState({ [`${name}Data`]: tableData, masterData });
      } else if (name === 'elemachine') {
        if (tableData[iIndex].bDefault === true) {
          masterData.sMachineId = tableData[iIndex].sMachineId;
          masterData.handleType = masterData.handleType === 'add' ? 'add' : 'update';
          tableData.forEach((item, i) => {
            if (i !== iIndex) {
              tableData[i].bDefault = false;
            }
          });
        } else if (tableData[iIndex].bDefault === false) {
          masterData.handleType = masterData.handleType === 'add' ? 'add' : 'update';
          masterData.sMachineId = undefined;
        }
        this.props.onSaveState({ [`${name}Data`]: tableData, masterData });
      } else {
        if (commonUtils.isNotEmptyStr(masterData.handleType)) {
          masterData.handleType = masterData.handleType === 'add' ? 'add' : 'update';
        }
        this.props.onSaveState({ [`${name}Data`]: tableData, masterData });
      }
    };

    /*  计算方案 计算公式设计点击事件  */
    handleButtonChange = (sName, value) => {
      /* 改变公示显示值 */
      const { masterData } = this.props;
      const sFormulaMemo = (Object.keys(masterData).length > 0 && masterData.sFormulaMemo !== undefined) ? masterData.sFormulaMemo : '';
      if (sName === 'systemFunction') {
        if (value === 'sysMaxInteger') {
          value = '最大整数(变量,0)';
        } else if (value === 'sysRounding') {
          value = '四舍五入(变量,0)';
        } else if (value === 'sysMinInteger') {
          value = '最小整数(变量,0)';
        }
      } else if (sName === 'bussinessFunction') {
        if (value === 'serviceMaterialsStocks') {
          value = '(材料名称,材料规格,仓库名称,自定义项)';
        } else if (value === 'serviceFinishedInventory') {
          value = '(成品名称,仓库名称,自定义项)';
        } else if (value === 'serviceMaterialCostPrice') {
          value = '(材料名称)';
        }
      }
      const changeFormula = `${sFormulaMemo}${value}`;
      masterData.sFormula = changeFormula;
      masterData.sFormulaMemo = changeFormula;
      masterData.handleType = masterData.handleType === 'add' ? 'add' : 'update';
      this.props.onSaveState({ masterData });
    };

    /** 修改主表数据 */
    handleMasterChange = (name, sFieldName, changeValue, sId, dropDownData) => {
      const { sModelsType, masterConfig } = this.props;
      const addState = this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, true);
      let { masterData } = addState;
      if (sModelsType === 'system/sisformulaInfo' && sFieldName === 'sFormulaMemo') {
        masterData.sFormula = changeValue.sFormulaMemo;
      } else if (sModelsType === 'sis/paymentTerms' && sFieldName === 'sType') {
        const { rowGdsconfig } = masterConfig;
        const newMasterData = {};
        newMasterData.handleType = masterData.handleType;
        newMasterData.sFormId = masterData.sFormId;
        newMasterData.sId = masterData.sId;
        newMasterData.sName = masterData.sName;
        newMasterData.sType = masterData.sType;

        if (changeValue.sType === 'deliver') {
          newMasterData.iAfterDeliverDay = masterData.iAfterDeliverDay;
          const threeRow = masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sName === 'iAfterDeliverDay');
          if (rowGdsconfig.length > 2) {
            rowGdsconfig.splice(2, 1, { gdsconfigformslave: threeRow });
          } else {
            rowGdsconfig.push({ gdsconfigformslave: threeRow });
          }
        } else if (changeValue.sType === 'month') {
          newMasterData.iDay = masterData.iDay;
          newMasterData.iMonth = masterData.iMonth;
          const threeRow = masterConfig.gdsconfigformslave.filter(item => item.bVisible && (item.sName === 'iMonth' || item.sName === 'iDay'));
          if (rowGdsconfig.length > 2) {
            rowGdsconfig.splice(2, 1, { gdsconfigformslave: threeRow });
          } else {
            rowGdsconfig.push({ gdsconfigformslave: threeRow });
          }
        } else if (rowGdsconfig.length > 2) {
          rowGdsconfig.splice(2, 1);
        }
        masterData = newMasterData;
      }
      this.props.onSaveState({
        masterData, masterConfig, ...addState,
      });
    };

    /* 计算方案 校验公式 功能 */
    handleField = async () => {
      const { sModelsId, masterData, sModelsType } = this.props;
      if (sModelsType === 'system/sisformulaInfo') {
        const { token } = this.props.app;
        const value = {
          handleType: 'check',
          sFormulaText: masterData.sFormulaMemo,
          sClientType: '1',
        };
        const dataUrl = `${commonConfig.server_host}replaceField/checkReplaceField?sModelsId=${sModelsId}`;
        const { data } = await commonServices.postValueService(token, value, dataUrl);
        if (data.code === 1) {
          message.success(data.msg);
        } else {
          this.props.getServiceError(data);
        }
      }
    };
    render() {
      const { masterData } = this.props;
      const imgSrc = commonBusiness.handleAddIcon(masterData);
      return (
        <ChildComponent
          {...this.props}
          {...this.state}
          onToggle={this.handleToggle}
          onAdd={this.handleAdd}
          onCancel={this.handleCancel}
          onEdit={this.handleEdit}
          onDel={this.handleDel}
          onSubmit={this.handleValidateSave}
          onReturnForm={this.handleForm}
          onBtnFirst={this.handleSearchData.bind(this, 'first')}
          onBtnPrior={this.handleSearchData.bind(this, 'up')}
          onNext={this.handleSearchData.bind(this, 'next')}
          onBtnLast={this.handleSearchData.bind(this, 'end')}
          onChangeInvalid={this.handleInvalid}
          onDataChange={this.handleTableChange}
          imgSrc={imgSrc}
          onButtonChange={this.handleButtonChange.bind(this)}
          onField={this.handleField.bind(this)}
          onChange={this.handleMasterChange}
        />
      );
    }
  };
};
